package com.yang.action;

import com.yang.entity.Order;
import com.yang.service.OrderService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;

@WebServlet("/updateOrder")
public class OrderUpdateAction extends HttpServlet {
    OrderService orderService = new OrderService();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Order order = new Order();
        String id = req.getParameter("id");
        order.setId(id);
        String userName = req.getParameter("userName");
        order.setUserName(userName);
        String address = req.getParameter("address");
        order.setAddress(address);
        String creationTime = req.getParameter("creationTime");
        order.setCreationTime(Date.valueOf(creationTime));
        String tel = req.getParameter("tel");
        order.setTel(tel);
        String totalAmount = req.getParameter("totalAmount");
        String status = req.getParameter("status");
        order.setStatus(Integer.parseInt(status));
        String userId = req.getParameter("userId");
        order.setUserId(Integer.parseInt(userId));
        int num = orderService.updateOrderById(order);
        resp.setContentType("text/text;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.print(num);
        out.flush();
        out.close();
    }
}

